package com.java.dormitorymanager.mvc.view;

import com.java.dormitorymanager.pojo.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

/**
 * @program: DormitoryManager
 * @description: 添加女同学至女宿舍的界面
 * @author: ShuangChenYue
 * @create: 2021-05-18 21:27
 **/
@WebServlet(value = "/ViewAddFSToDorm")
public class ViewAddFSToDormServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        System.out.println("点击宿舍行的添加学生进入此页面");
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html");
        //先获取一下上个请求传过来的dornum，我们要传给下个请求
        String dormNumber = (String) req.getAttribute("dormNumber");
        PrintWriter out = resp.getWriter();

        out.println("<!DOCTYPE html>");
        out.println("<html lang=\"en\">");
        out.println("<meta charset=\"UTF-8\">");
        out.println("<title>女学生分配宿舍</title>");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-dorm/addStudentsToDorm.css\">");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-other/doIcon.css\">");
        out.println("</head>");
        out.println("<body>");
        out.println("<div id=\"divTitle\">");
        out.println("<h1 id=\"h01\">Add Female Students To Dorm</h1>");
        out.println("</div>");
        out.println("<div id=\"div01\">");
        out.println("<h3 class=\"ListName\">FemaleStudentsWithoutDorm</h3>");
        out.println("<table class=\"table01\">");
        out.println("<tr class=\"tr01\">");
        out.println("<td>ID</td>");
        out.println("<td>姓名</td>");
        out.println("<td>学号</td>");
        out.println("<td>性别</td>");
        out.println("<td>宿舍</td>");
        out.println("<td>操作</td>");
        out.println("</tr>");
        List<Student> allFemaleStudentsWithoutDormList = (List<Student>) req.getAttribute("allFemaleStudentsWithoutDormList");
        Iterator<Student> iterator = allFemaleStudentsWithoutDormList.iterator();
        while (iterator.hasNext())
        {
            Student allFemaleStudentsWithoutDorm = iterator.next();
            out.println("<tr class=\"tr02\">");
            out.println("<td style=\"text-align: center\">"+allFemaleStudentsWithoutDorm.getId()+"</td>");
            out.println("<td>"+allFemaleStudentsWithoutDorm.getName()+"</td>");
            out.println("<td>"+allFemaleStudentsWithoutDorm.getStunum()+"</td>");
            out.println("<td>"+allFemaleStudentsWithoutDorm.getGender()+"</td>");
            out.println("<td>"+allFemaleStudentsWithoutDorm.getDornum()+"</td>");
            out.println("<td><a href=\"/DormitoryManager/mvc/addFSToDorm.do?dormNumber="+dormNumber+"&id="+allFemaleStudentsWithoutDorm.getId()+"\"><i class=\"iconfontU addIcon\" title=\"确认添加\">&#xe624;</i></a></td>");
            out.println("</tr>");
        }


        out.println("</table>");
        out.println("</div>");
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();
    }
}
